home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 1.5 KB | 62 lines | [TEXT/ttxt] |
- -- <<<
- -- Filename: BOUNCING.SX
-
- -- Purpose: Demonstrates how to make an object controlled by gravity in a space.
-
- -- Other Files Required: (none)
-
- -- Instructions to User: You should see a black ball bouncing around in a window.
- -- To start the ball bouncing again, type "restart myBall"
-
- -- Specialized Classes: Ball
-
- ------------------------------------------------------------------------
-
- -- Make a projectile by defining a class that
- -- inherits from both TwoShape and Projectile
- class Ball (TwoDShape, Projectile)
- end
-
- -- Create an instance of Ball and initialize it
- method init self {class Ball} #rest args ->
- (
- apply nextMethod self args
- self.x := 50
- self.y := 50
- self.elasticity := 1
- self.velocity := new Point x:-8.0 y:4.0
- )
-
- -- Method to restart the ball bouncing
- method restart self {class Ball} ->
- (
- self.x := 50
- self.y := 50
- self.velocity := new Point x:-8.0 y:4.0
- )
-
- -- Set up the window
- global myWindow := new Window boundary:(new Rect x2:400 y2:250) fill:blackBrush
- myWindow.x := 40
- myWindow.y := 40
- show myWindow
-
- -- Create the controllers
- global myGravity := new Gravity space:myWindow
- myGravity.wholeSpace := true
-
- global myBounce := new Bounce space:myWindow
- myBounce.wholeSpace := true
-
- global myMovement := new Movement space:myWindow
- myMovement.wholeSpace := true
-
- -- Create an instance of Ball and append it to the space
- global myBall := new Ball target:(new Oval x2:20 y2:20) fill:whiteBrush
- prepend myWindow myBall
-
-
- -- To start the ball bouncing again, type "restart myBall"
-
-
-